# -*- coding: utf-8 -*-
# @Time    :2020/5/25 21:20
# @Author  :lyq

from django.core.paginator import Paginator

# 分页的工具函数
def get_objects_page(object_list=None, pageNum=1, perPage=12):
    # 获取一个分页对象
    pages = Paginator(object_list, per_page=perPage)
    # 保证pageNum在合理范围
    pageNum = int(pageNum)
    if pageNum < 1:
        pageNum = 1
    if pageNum > pages.num_pages:
        pageNum = pages.num_pages
    # 获取相应页面
    page = pages.page(pageNum)

    return page, page.object_list

